<!--三级分类树形展示组件-->
<template>
  <el-tree
      :data="categoryList"
      node-key="id"
      :expand-on-click-node="false"
      :props="defaultProps"
      @node-click="selectNode"
  >
  </el-tree>
</template>

<script setup>
import {onMounted, ref, defineEmits} from "vue";
import {getAllCategoryToTree} from "@/api/home/goods/category";

const emits = defineEmits(['select'])
const defaultProps = {
  label: 'name',
  children: 'children'
}
let categoryList = ref([])
onMounted(() => {
  getAllCategory()
})

function getAllCategory() {
  getAllCategoryToTree().then(res => {
    categoryList.value = res.data
  })
}

function selectNode(data, node) {
  if (node.level == 3) {
    emits('select', data)
  }
}

</script>

<style scoped>

</style>
